package com.exam.sacrifice.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.exam.commonbiz.util.CommonCallBack;
import com.exam.commonbiz.util.OnFastClickListener;
import com.exam.commonbiz.util.ScreenUtil;
import com.exam.sacrifice.App;
import com.exam.sacrifice.R;

public class JiSiActivityDialog {

    public void show(Context context, CommonCallBack commonCallBack) {
        LinearLayout layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.dialog_layout_jisi_activity, null);
        Dialog dialog = new Dialog(context);
        dialog.setContentView(layout);
        dialog.show();
        setPosition(dialog);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        layout.findViewById(R.id.btn_qingming).setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                if (commonCallBack != null) {
                    commonCallBack.callback(0, null);
                }
            }
        });

        layout.findViewById(R.id.btn_zhongyuan).setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                if (commonCallBack != null) {
                    commonCallBack.callback(1, null);
                }
            }
        });

        layout.findViewById(R.id.iv_close).setOnClickListener(new OnFastClickListener() {
            @Override
            public void onFastClick(View v) {
                dialog.dismiss();
//                DialogUtils.showCustomConfirmDialog((Activity) context,
//                        "系统提示",
//                        "确认活动弹窗吗，关闭后下次启动app才会显示哦？",
//                        "关闭",
//                        "取消",
//                        new CommonCallBack() {
//                            @Override
//                            public void callback(int postion, Object object) {
//                                if (postion == 0) {
//
//                                }
//                            }
//                        });
            }
        });
    }

    public void setPosition(Dialog dialog) {

        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);

        lp.width = (int) (ScreenUtil.getScreenWidth(App.getInstance()) * 0.8);
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
    }
}
